/**
 * @title: AuthorityRuleMysqlConverter
 * @projectName mscloud
 * @Description TODO
 * @Author
 * @Date 2022/2/18 16:17
 */
package com.atguigu.springcloud.cloudsentinelgatewaydevelop.sentinel.convert.impl;

import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.bean.dto.SentinelAuthorityRuleDTO;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.sentinel.convert.PullConverter;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Data
@Component
public class AuthorityRuleMysqlConverter implements PullConverter<List<SentinelAuthorityRuleDTO>, List<AuthorityRule>> {
    private long recommendRefreshMs=10000;
    @Override
    public List<AuthorityRule> convert(List<SentinelAuthorityRuleDTO> source) {
        return source.stream().map(
                item->{
                    AuthorityRule authorityRule=new AuthorityRule();
                    //JSONObject jsonObject = JSON.parseObject(item);
                    authorityRule.setResource(item.getResource());
                    authorityRule.setLimitApp(item.getLimitApp());
                    authorityRule.setStrategy(item.getStrategy());
                    return authorityRule;
                }
        ).collect(Collectors.toList());
    }
}
